package com.ruoyi.quartz.task;

import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysStudent;
import com.ruoyi.system.service.ISysStudentService;

/**
 * 学生信息定时任务
 * 
 * @author ruoyi
 */
@Component("studentTask")
public class StudentTask
{
    @Autowired
    private ISysStudentService studentService;
    
    // 姓氏列表
    private static final String[] SURNAMES = {"张", "王", "李", "赵", "刘", "陈", "杨", "黄", "周", "吴", "徐", "孙", "马", "朱", "胡", "郭", "何", "高", "林", "罗"};
    
    // 名字列表
    private static final String[] NAMES = {"伟", "芳", "娜", "秀英", "敏", "静", "丽", "强", "磊", "军", "洋", "勇", "艳", "杰", "娟", "涛", "明", "超", "秀兰", "霞"};
    
    // 个人介绍列表
    private static final String[] INTRODUCTIONS = {
        "热爱学习，勤奋努力，善于思考",
        "性格开朗，乐于助人，团结同学",
        "积极向上，勇于探索，敢于创新",
        "责任心强，做事认真，追求卓越",
        "兴趣广泛，多才多艺，全面发展",
        "思维敏捷，学习能力强，成绩优异",
        "诚实守信，品行端正，尊敬师长",
        "热爱运动，身体健康，充满活力",
        "善于沟通，团队协作能力强",
        "目标明确，规划清晰，执行力强"
    };
    
    /**
     * 随机生成一个学生信息并插入到表中
     */
    public void generateRandomStudent()
    {
        Random random = new Random();
        
        // 创建学生对象
        SysStudent student = new SysStudent();
        
        // 随机生成姓名
        String surname = SURNAMES[random.nextInt(SURNAMES.length)];
        String name = NAMES[random.nextInt(NAMES.length)];
        String fullName = surname + name;
        student.setStudentName(fullName);
        
        // 随机生成性别（0男 1女）
        String sex = random.nextBoolean() ? "0" : "1";
        student.setSex(sex);
        
        // 随机生成个人介绍
        String introduction = INTRODUCTIONS[random.nextInt(INTRODUCTIONS.length)];
        student.setIntroduction(introduction);
        
        // 设置状态为正常
        student.setStatus("0");
        
        // 设置删除标志为存在
        student.setDelFlag("0");
        
        // 随机生成头像URL（示例）
        student.setAvatar("https://example.com/avatar/" + random.nextInt(100) + ".jpg");
        
        // 设置创建时间
        student.setCreateTime(DateUtils.getNowDate());
        
        // 保存到数据库
        int result = studentService.insertSysStudent(student);
        
        if (result > 0)
        {
            System.out.println(StringUtils.format("成功生成学生信息：姓名：{}，性别：{}，ID：{}", 
                fullName, "0".equals(sex) ? "男" : "女", student.getStudentId()));
        }
        else
        {
            System.out.println("生成学生信息失败");
        }
    }
    
    /**
     * 批量生成指定数量的学生信息
     * 
     * @param count 生成数量
     */
    public void generateBatchStudents(String count)
    {
        try 
        {
            int num = Integer.parseInt(count);
            System.out.println("开始批量生成学生信息，数量：" + num);
            
            for (int i = 0; i < num; i++)
            {
                generateRandomStudent();
            }
            
            System.out.println("批量生成学生信息完成，共生成：" + num + "条记录");
        }
        catch (NumberFormatException e)
        {
            System.out.println("参数格式错误，请输入有效的数字");
        }
    }
}